<?php

use Biz\service\BrandUser as sBrandUser;
use Doraemon\tools\ActionLog;
use Biz\service\trade\UserAddress;
use Biz\tools\GoodsExposureLog;

/**
 * @deprecated
 */
class GoodsListAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_NOTHING;

    public function main()
    {

        $actionLogMap = [
            'default',
            'new',
            'price_asc',
            'price_desc',
        ];

        $banner_id = $this->getRequest()->getPost('banner_id', 0);

        $uid = $this->getRequest()->getPost('uid', 0);
        $sort_type = $this->getRequest()->getPost('sort_type', 0);
        $province_id = $this->getRequest()->getPost('province_id', 0);
        $cityId = $this->getRequest()->getPost('city_id', 0);
        $page = $this->getRequest()->getPost('page', 1);
		$userCityId = UserAddress::getUserDefaultCityCode($uid);
		$areaCode = $userCityId ? $userCityId : ($cityId ? $cityId : $province_id);
        if ($banner_id) {
            $goodsList = sBrandUser::getAllGoods(0, $banner_id, $areaCode, $sort_type, $this->appVersion, $page);
        } else {
            $goodsList = sBrandUser::getAllGoods($uid, '', $areaCode, $sort_type, $this->appVersion, $page);

            ActionLog::log($this->uid, [
                'uid' => $this->uid,
                'shop_id' => $uid,
                'page' => $page,
                'sort_type' => $sort_type,
            ], ActionLog::SHOP_GOODS_LIST);
        }
        ActionLog::log($this->uid, ['page' => $page, 'sort_type' => $actionLogMap[$sort_type]], ActionLog::BIZ_SHOP_GOODS_LIST);

        $this->setSuccess($goodsList);
        GoodsExposureLog::addLog($this->getRequest(), $goodsList);
    }
}